/*
 * @Author: your name
 * @Date: 2020-10-08 17:08:27
 * @LastEditTime: 2021-04-01 17:41:55
 * @LastEditors: Please set LastEditors
 * @Description: In User Settings Edit
 * @FilePath: \solaxcloud\src\router\index.js
 */

import Vue from 'vue'
import VueRouter from 'vue-router'
import yhRouter from './index_yh'
import wdRouter from './index_wd'

Vue.use(VueRouter)
const routes = [
    { path: "/", redirect: "/login" },
    {
        path: '/login',
        name: 'login',
        component: () =>
            import ( /* webpackChunkName: "login" */ '../views/login/login.vue')
    }, {
        path: '/selectPlatform',
        name: 'selectPlatform',
        component: () =>
            import ( /* webpackChunkName: "selectPlatform" */ '../views/selectPlatform.vue')
    }, {
        path: '/cs',
        name: 'cs',
        component: () =>
            import ( /* webpackChunkName: "cs" */ '../views/cs.vue')
    }, {
        path: '/svg',
        name: 'svg',
        component: () =>
            import ( /* webpackChunkName: "svg" */ '../views/svg.vue')
    }, {
        path: '/svg2',
        name: 'svg2',
        component: () =>
            import ( /* webpackChunkName: "svg2" */ '../views/svg2.vue')
    }, {
        path: '/save',
        name: 'save',
        component: () =>
            import ( /* webpackChunkName: "svg2" */ '../views/save.vue')
    }, {
        path: '/csForm',
        name: 'csForm',
        component: () =>
            import ( /* webpackChunkName: "csForm" */ '../views/csForm.vue')
    }, {
        path: '/canvas',
        name: 'canvas',
        component: () =>
            import ( /* webpackChunkName: "selectPlatform" */ '../views/canvas.vue')
    }, {
        path: '/present',
        name: 'present',
        component: () =>
            import ( /* webpackChunkName: "selectPlatform" */ '../views/present.vue')
    }, {
        path: '/organizeView',
        name: 'organizeView',
        component: () =>
            import ( /* webpackChunkName: "organizeView" */ '../views/companyindex/organizeView/organizeView.vue')
    }, , {
        path: '/topology',
        name: 'topology',
        component: () =>
            import ( /* webpackChunkName: "organizeView" */ '../views/companyindex/topology/topology.vue')
    }, {
        path: '/home',
        name: 'home',
        component: () =>
            import ( /* webpackChunkName: "home" */ '../views/Home.vue'),
        children: [...yhRouter, ...wdRouter,
            {
                path: '/404', // 页面不存在的情况下会跳到404页面 @@@@该路由放在最下面
                name: 'notFound',
                component: () =>
                    import ( /* webpackChunkName: "404" */ '../views/404/index.vue')
            }
        ]
    },
    {
        path: '*', // 页面不存在的情况下会跳到404页面 @@@@该路由放在最下面
        name: 'notFound',
        redirect: '/404',
    }

]

const router = new VueRouter({
    routes
})

router.beforeEach((to, from, next) => {
        if (to.path == '/') {
            next('/login');
            return
        }

        next();
    })
    /**
     * 跳转登陆页面强制刷新，相当于F5
     */
router.afterEach((to, from) => {
    if (from.path != '/Login' && from.path != '/' && to.path == '/Login') {
        window.location.reload();
    }
})

export default router